package com.ltv.xiangqiplugin.controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.ltv.xiangqiplugin.models.Messages;
import com.ltv.xiangqiplugin.views.ChessApp;

public class OptionControl implements ActionListener {
	private ChessApp mainApp;
	public OptionControl(ChessApp mainApp) {
		super();
		this.mainApp = mainApp;
	}
	
	@Override
	public void actionPerformed(ActionEvent event) {
		String command = event.getActionCommand();
		
		if (command.compareTo("OK") == 0) {
			try {
				Messages.getInstance().setLang(mainApp.getOptionView().getLanguage());
			} catch (Exception e) {
				e.printStackTrace();
			}
			Messages.getInstance().setBoardSize(mainApp.getOptionView().getBoardSize());
			Messages.getInstance().setTheme(mainApp.getOptionView().getTheme());
			
			Messages.getInstance().notifyObservers();
			
			mainApp.getOptionView().setVisible(false);
		} else if (command.compareTo("CANCEL") == 0) {
			mainApp.getOptionView().correctSelectedLanguageIndex();
			mainApp.getOptionView().setVisible(false);
		}
	}
}
